package com.company.game00;

import java.util.LinkedList;
import java.util.List;

public class BulletsPool {

    private static final List<Bullet> POOL = new LinkedList<>();
    private static final int INIT_POOL_SIZE = 10;
    private static final int MAX_POOL_SIZE = 100;

    static {
        for (int i = 0; i < INIT_POOL_SIZE; i++) {
            POOL.add(new Bullet());
        }
    }

    public static Bullet get() {
        if (POOL.size() > 0) {
            return POOL.remove(0);
        } else {
            return new Bullet();
        }
    }

    public static void ret(Bullet bullet) {
        if (POOL.size() < MAX_POOL_SIZE) {
            POOL.add(bullet);
        }
    }
}
